Codeforces Round Problem C. Basil's Garden Full Solution In C++